$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'app/coupon/list',
        datatype: "json",
        colModel: [	
        	{ label: '名称', name: 'title', index: "title", width: 80, key: true },
			{ label: '类别', name: 'category',  width: 40},
			{ label: '原价', name: 'zk_final_price',  width: 40},
			{ label: '佣金率', name: 'commission_rate', width: 40 },
			{ label: '券详情', name: 'coupon_info',  width: 40},
			{ label: '结束时间', name: 'coupon_end_time', width: 40 },
			{ label: '开始时间', name: 'coupon_start_time', width: 40 },
			/*{ label: '样图', name: 'pict_url', width: 70,formatter: function(value, options, row){
				return '<img width="110" height="110" src="'+value+'"/>';
				} },
			{ label: '领券', name: 'coupon_click_url', width: 70,formatter: function(value, options, row){
				return '<a href="'+value+'" target="_blank">点击领券</a>';
				} },*/
			{ label: '剩余', name: 'coupon_remain_count',  width: 40,hidden:true},
			{ label: '', name: 'num_iid',  width: 40,hidden:true},
			{ label: '总量', name: 'coupon_total_count',  width: 40,hidden:true},
			{ label: '别名', name: 'nick',  width: 40,hidden:true},
			{ label: '体量', name: 'volume',  width: 40,hidden:true},
			{ label: '用户类型', name: 'user_type',  width: 40,hidden:true},
			{ label: '商品地址', name: 'item_url',  width: 40,hidden:true},
			{ label: '店铺名称', name: 'shop_title',  width: 40,hidden:true},
			{ label: '缩略图', name: 'small_imageso',  width: 40,hidden:true},
			{ label: '缩略图', name: 'small_imagest',  width: 40,hidden:true},
			{ label: '缩略图', name: 'small_imagesth',  width: 40,hidden:true},
			{ label: '缩略图', name: 'small_imagesf',  width: 40,hidden:true},
			{ label: '商品描述', name: 'item_description',  width: 40,hidden:true},
			{ label: '卖家', name: 'seller_id',  width: 40,hidden:true},
			{ label: '样图', name: 'pict_url', width: 70},
			{ label: '领券', name: 'coupon_click_url', width: 70}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 50,
		rowList : [50,30,10],
        rownumbers: true, 
        rownumWidth: 50, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			goodName: null,
			cat:null
		},
		showList: true,
		title:null,
		sysCodeList:{}
	},
	created: function () {
		$.get(baseURL + "sys/syscode/listgoodcat", function(r){
            vm.sysCodeList = r.sysCodeList;
        });
	  },
	methods: {
		query: function () {
			vm.reload();
		},
		reload: function () {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                postData:{'goodName': vm.q.goodName,'cat':vm.q.cat},
                page:page
            }).trigger("reloadGrid");
		},
		importGood:function(){
			var indexx = layer.load(0, {shade: false}); 
			var goods = new Array();
			var ids = getSelectedRows();
			for(i=0; i<ids.length; i++){
				goods.push($("#jqGrid").jqGrid("getRowData",ids[i]));
			}
			$.ajax({
				type: "POST",
			    url: baseURL + "app/goodcoupon/saveList",
                contentType: "application/json",
			    data: JSON.stringify(goods),
			    success: function(r){
			    	layer.close(indexx);
					if(r.code == 0){
						alert('导入成功', function(){
                            vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		}
	}
});